#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "playerwidget.h"
#include "playerlayout.h"
#include "playerapplication.h"
#include "frequencelist.h"
#include "programlist.h"
#include <QTreeWidgetItem>


namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    void setLayoutMode(PlayerLayout::Mode mode);

    int getCurrentIndex();
    void setCurrentIndex(int idx);

    void stopAll();

    void stop(int index);

    void showFull(bool fullscreen);

    void startLoop();
    void stopLoop();
    bool isLooping();

	PlayerApplication& getApp();

    void start(int index, const QString& url);

    QString getUser();

protected:
    virtual void resizeEvent(QResizeEvent *event);
    virtual void showEvent(QShowEvent *event);
    virtual void timerEvent(QTimerEvent *);
    virtual void closeEvent(QCloseEvent * event);
    virtual void keyPressEvent(QKeyEvent *event);

private slots:
    void onPlayerClicked(int index);
    void onPlayerRClicked(int index);
    void onPlayerDbclicked(int index);
    void onPlayerMediaEnd(int index);
    void onPlayerDragDropped(int index, const QString& url, const QString& id, const QString& name);

    void on_actionFullscreen_triggered();

    void on_actionLoop_triggered();

    void on_actionfreq_triggered();

    void on_actionprogram_triggered();

    void on_actionconfig_triggered();

    void on_actionusers_triggered();

    void on_actionmanage_triggered();

    void on_actionexit_triggered();

    void on_pushButtonStop_clicked();
    void on_pushButtonStopAll_clicked();

    void on_actionOne_triggered();

    void on_actionFour_triggered();

    void on_actionNine_triggered();

    void on_actionSixteen_triggered();

    void on_clickClearFreq();
    void on_clickClearProgram();
    void on_clickClearLoop();

    void on_actionstop_triggered();

    void on_actionstopAll_triggered();

    void on_actionhideTool_triggered();

private:
    void setupPlayerWidget();
    void setupSignal();
    void layoutPlayer(PlayerLayout::Mode mode);

    void setupProgram();

    void refreshProgramTree();

    QTreeWidgetItem* findFreqItem(const std::string& num);

    void updateWindowTitle();

    void loopPlay();

private:



private:
    Ui::MainWindow *ui;

private:
    PlayerWidget*   m_playerWidgets[16];

    PlayerLayout    m_layout;
    PlayerLayout::Mode  m_layoutMode;
    PlayerLayout::Mode  m_lastMode;
    int m_currentIndex;

    bool    m_isLooping;


    tv::FrequenceList  m_freqList;
    tv::ProgramList     m_programList;
    tv::ProgramList     m_loopList;

    int     m_timerLoop;
    int     m_loopIndex;

};

#endif // MAINWINDOW_H
